package com.cci.kangdao.service.impl;


import com.cci.kangdao.aop.UserThreadLocal;
import com.cci.kangdao.dao.BusinessRegionTDao;
import com.cci.kangdao.dao.model.UserT;
import com.cci.kangdao.service.BusinessService;
import com.cci.kangdao.utilTool.ParameterTool;
import org.apache.log4j.Logger;
import org.json.JSONObject;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("BusinessService")
public class BusinessServiceImpl implements BusinessService {

	private Logger log = Logger.getLogger(this.getClass().getName());
	@Resource
	private BusinessRegionTDao businessRegionTDao;

	//服务工单经理获取区域集合
	public ModelAndView getRegionList(Map<String, Object> map) {
		HttpServletResponse response = (HttpServletResponse) map.get("response");
		UserT userT = UserThreadLocal.get();
		JSONObject obj = new JSONObject();  //声明返给前端json对象
		try {
			List<Map<String,Object>> regionList = businessRegionTDao.getRegionListByUserId(userT.getId());
			Map<String,Object> regionListMap = new HashMap<>();
			regionListMap.put("regionList",regionList);
			obj.put("data", regionListMap);
			obj.put("status", 0);
			obj.put("msg", "success");
			ParameterTool.writeResponse(response, obj.toString());
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);
			ParameterTool.writeErrorResponse(response);
			// 主动回滚事务
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
		}
		return null;
	}

	


}
